package com.amazon.ags.client.leaderboards;

import android.text.TextUtils;
import android.util.Log;
import com.amazon.ags.api.AGResponseHandle;
import com.amazon.ags.api.AmazonGamesStatus;
import com.amazon.ags.api.ErrorCode;
import com.amazon.ags.api.RequestResponse;
import com.amazon.ags.api.leaderboards.GetLeaderboardPercentilesResponse;
import com.amazon.ags.api.leaderboards.GetLeaderboardsResponse;
import com.amazon.ags.api.leaderboards.GetPlayerScoreResponse;
import com.amazon.ags.api.leaderboards.GetScoresResponse;
import com.amazon.ags.api.leaderboards.LeaderboardsClient;
import com.amazon.ags.api.leaderboards.SubmitScoreResponse;
import com.amazon.ags.client.AmazonGamesService;
import com.amazon.ags.client.GCResponseHandleImpl;
import com.amazon.ags.client.RequestResponseImp;
import com.amazon.ags.constants.LeaderboardFilter;

public class LeaderboardsClientImpl
  implements LeaderboardsClient
{
  private static final String FEATURE_NAME = "LB";
  private static final String TAG = "LB_" + LeaderboardsClientImpl.class.getSimpleName();
  private final AmazonGamesService amazonGamesService;
  private final LeaderboardsService leaderboardsService;

  public LeaderboardsClientImpl(AmazonGamesService paramAmazonGamesService, LeaderboardsService paramLeaderboardsService)
  {
    this.amazonGamesService = paramAmazonGamesService;
    this.leaderboardsService = paramLeaderboardsService;
  }

  private boolean canSubmitScore()
  {
    AmazonGamesStatus localAmazonGamesStatus = this.amazonGamesService.getStatus();
    switch (1.$SwitchMap$com$amazon$ags$api$AmazonGamesStatus[localAmazonGamesStatus.ordinal()])
    {
    default:
      return true;
    case 1:
    case 2:
    case 3:
    case 4:
    }
    return false;
  }

  public final AGResponseHandle<GetLeaderboardsResponse> getLeaderboards(Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (!this.amazonGamesService.isReady())
    {
      Log.d(TAG, "Service not bound");
      localGCResponseHandleImpl.setResponse(new GetLeaderboardsResponseImp(18, ErrorCode.SERVICE_NOT_READY));
      return localGCResponseHandleImpl;
    }
    this.leaderboardsService.getLeaderboards(localGCResponseHandleImpl);
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<GetPlayerScoreResponse> getLocalPlayerScore(String paramString, LeaderboardFilter paramLeaderboardFilter, Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (!this.amazonGamesService.isReady())
    {
      Log.d(TAG, "Service not ready");
      localGCResponseHandleImpl.setResponse(new GetPlayerScoreResponseImp(18, ErrorCode.SERVICE_NOT_READY));
      return localGCResponseHandleImpl;
    }
    this.leaderboardsService.requestLocalPlayerScore(paramString, paramLeaderboardFilter, localGCResponseHandleImpl);
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<GetLeaderboardPercentilesResponse> getPercentileRanks(String paramString, LeaderboardFilter paramLeaderboardFilter, Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (!this.amazonGamesService.isReady())
    {
      Log.d(TAG, "Service not ready");
      localGCResponseHandleImpl.setResponse(new GetLeaderboardPercentilesResponseImp(18, ErrorCode.SERVICE_NOT_READY));
      return localGCResponseHandleImpl;
    }
    this.leaderboardsService.getPercentileRanks(paramString, paramLeaderboardFilter, localGCResponseHandleImpl);
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<GetScoresResponse> getScores(String paramString, LeaderboardFilter paramLeaderboardFilter, int paramInt1, int paramInt2, Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (!this.amazonGamesService.isReady())
    {
      Log.d(TAG, "Service not ready");
      localGCResponseHandleImpl.setResponse(new GetScoresResponseImp(18, ErrorCode.SERVICE_NOT_READY));
      return localGCResponseHandleImpl;
    }
    this.leaderboardsService.requestScores(paramString, paramLeaderboardFilter, paramInt1, paramInt2, localGCResponseHandleImpl);
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<RequestResponse> showLeaderboardOverlay(String paramString, Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (TextUtils.isEmpty(paramString))
    {
      Log.d(TAG, "Provided leaderboard ID is empty.");
      localGCResponseHandleImpl.setResponse(new RequestResponseImp(18, ErrorCode.DATA_VALIDATION_ERROR));
      return localGCResponseHandleImpl;
    }
    if ((this.amazonGamesService.isReady()) || (this.amazonGamesService.getStatus() == AmazonGamesStatus.SERVICE_NOT_OPTED_IN))
    {
      this.leaderboardsService.showRanksOverlay(paramString, localGCResponseHandleImpl);
      return localGCResponseHandleImpl;
    }
    Log.d(TAG, "Service not ready");
    localGCResponseHandleImpl.setResponse(new RequestResponseImp(18, ErrorCode.SERVICE_NOT_READY));
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<RequestResponse> showLeaderboardsOverlay(Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if ((this.amazonGamesService.isReady()) || (this.amazonGamesService.getStatus() == AmazonGamesStatus.SERVICE_NOT_OPTED_IN))
    {
      this.leaderboardsService.showLeaderboardsOverlay(localGCResponseHandleImpl);
      return localGCResponseHandleImpl;
    }
    Log.d(TAG, "Service not ready");
    localGCResponseHandleImpl.setResponse(new RequestResponseImp(18, ErrorCode.SERVICE_NOT_READY));
    return localGCResponseHandleImpl;
  }

  public final AGResponseHandle<SubmitScoreResponse> submitScore(String paramString, long paramLong, Object[] paramArrayOfObject)
  {
    GCResponseHandleImpl localGCResponseHandleImpl = new GCResponseHandleImpl(paramArrayOfObject);
    if (!canSubmitScore())
    {
      Log.d(TAG, "Service not authorized");
      localGCResponseHandleImpl.setResponse(new SubmitScoreResponseImp(18, ErrorCode.SERVICE_NOT_READY));
      return localGCResponseHandleImpl;
    }
    this.leaderboardsService.submitScore(paramString, paramLong, localGCResponseHandleImpl);
    return localGCResponseHandleImpl;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.client.leaderboards.LeaderboardsClientImpl
 * JD-Core Version:    0.6.2
 */